import * as actionTypes from './constant';
import { getCategoryRequest } from '@/services/main/category';
import { getDepartmentRequest } from '../../../services/main/department';
import { getGoodsRequest } from '../../../services/main/goods';
import { getRoleRequest } from '../../../services/main/role';
import { getUserRequest } from '../../../services/main/user';
import { getDashboardRequest } from '../../../services/main/dashboard';

export const changeCategoryAction = () => {
  return async (dispatch) => {
    await getCategoryRequest().then((res) => {
      dispatch({
        type: actionTypes.CHANGE_CATEGORY,
        categoryList: res.data,
      });
    });
  };
};

export const changeDepartmentAction = () => {
  return async (dispatch) => {
    await getDepartmentRequest().then((res) => {
      dispatch({
        type: actionTypes.CHANGE_DEPARTMENT,
        departmentList: res.data,
      });
    });
  };
};

export const changeGoodsAction = () => {
  return async (dispatch) => {
    await getGoodsRequest().then((res) => {
      dispatch({
        type: actionTypes.CHANGE_GOODS,
        goodsList: res.data,
      });
    });
  };
};

export const changeRolesAction = () => {
  return async (dispatch) => {
    await getRoleRequest().then((res) => {
      dispatch({
        type: actionTypes.CHANGE_ROLES,
        rolesList: res.data,
      });
    });
  };
};

export const changeUsersAction = () => {
  return async (dispatch) => {
    await getUserRequest().then((res) => {
      dispatch({
        type: actionTypes.CHANGE_USERS,
        usersList: res.data,
      });
    });
  };
};

export const changetDashboardAction = () => {
  return async (dispatch) => {
    await getDashboardRequest().then((res) => {
      dispatch({
        type: actionTypes.CHANGE_DASHBOARD,
        dashboardList: res.data,
      });
    });
  };
};
